package com.cam.framework.system.dept.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cam.framework.system.dept.domain.SysDeptDTO;
import com.cam.framework.system.dept.service.SysDeptService;
import com.cam.framework.utils.RestResult;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sys/dept")
public class SysDeptController {

    private final SysDeptService sysDeptService;

    public SysDeptController(SysDeptService sysDeptService) {
        this.sysDeptService = sysDeptService;
    }

    @GetMapping("tree")
    public RestResult tree(SysDeptDTO sysDeptDTO, Page<SysDeptDTO> page) {
        return RestResult.success();
    }

    @GetMapping("/list")
    public RestResult list(SysDeptDTO sysDeptDTO) {
        QueryWrapper<SysDeptDTO> queryWrapper = new QueryWrapper<>();
        List<SysDeptDTO> list = sysDeptService.findList(queryWrapper);
        return RestResult.success().put("list", list);
    }

    @GetMapping("find")
    public RestResult find(String id) {
        SysDeptDTO data = sysDeptService.findById(id);
        return RestResult.success().put("data", data);
    }

    @PostMapping("/save")
    public RestResult save(@RequestBody SysDeptDTO sysDeptDTO) {
        sysDeptService.save(sysDeptDTO);
        return RestResult.success("保存成功");
    }
}
